package com.site.wisdom_construction.util.tree;




import com.site.wisdom_construction.entity.scheduleModule.ProgressPlan;
import com.site.wisdom_construction.entity.scheduleModule.ProjectProgressPlan;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @author DYF
 */
public class ProgressPlanTreeUtil {

    public static Map<String, Object> mapArray = new LinkedHashMap<String, Object>();
    public List<ProgressPlan> menuCommon;
    public List<Object> list = new ArrayList<Object>();

    public List<Object> menuList(List<ProgressPlan> menu) { //controller层调用的方法   ，并将数据以list的形式返回
        this.menuCommon = menu;
        for (ProgressPlan x : menu) {
            Map<String, Object> mapArr = new LinkedHashMap<String, Object>();
            //判断是否为父极
            if (x.getIsparent().equals("true") && x.getFatherId() == (0)) {
                mapArr.put("id" , x.getId());
                mapArr.put("projectId" , x.getProjectId());
                mapArr.put("progressPlanName" , x.getProgressPlanName());
                mapArr.put("fatherId" , x.getFatherId());
                mapArr.put("leave" , x.getLeave());
                mapArr.put("isparent" , x.getIsparent());
                mapArr.put("status" , x.getStatus());
                //去子集查找遍历
                mapArr.put("child" , menuChild(x.getId()));
                list.add(mapArr);
            }
        }
        return list;
    }

    public List<?> menuChild(int id) { //子集查找遍历
        List<Object> lists = new ArrayList<Object>();
        for (ProgressPlan a : menuCommon) {
            Map<String, Object> childArray = new LinkedHashMap<String, Object>();
            if (a.getFatherId() == (id)) {
                childArray.put("id" , a.getId());
                childArray.put("projectId", a.getProjectId());
                childArray.put("projectProgressName" , a.getProgressPlanName());
                childArray.put("fatherId" , a.getFatherId());
                childArray.put("leave" , a.getLeave());
                childArray.put("isparent" , a.getIsparent());
                childArray.put("status" , a.getStatus());
                childArray.put("child" , menuChild(a.getId()));
                lists.add(childArray);
            }
        }
        return lists;
    }

}
